/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.trandio.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.naming.NamingException;
import org.trandio.model.ConfigVO;
import org.trandio.model.PlanoAFVO;
import org.trandio.util.ConexionDb;

/**
 *
 * @author root
 */
public class ConfigDAO implements ConfigInterface {

    @Override
    public ConfigVO traerConfig(int id) throws SQLException, NamingException {
         ConexionDb con = new ConexionDb();
        Connection conn;
        conn = con.traerConexion();

        String sql = "SELECT tb_configuracion.id, tb_configuracion.codigo,"
                   + "tb_configuracion.descripcion, tb_configuracion.nit,"
                   + "tb_configuracion.direccion, tb_configuracion.telefono,"
                   + "tb_configuracion.rutalogo, tb_configuracion.rutarips,"
                   + "tb_configuracion.prefijo_fact, tb_configuracion.cons_inifact,"
                   + "tb_configuracion.cons_finfact, tb_configuracion.cons_actfact,"
                   + "tb_sede.codigo_prestador cod_pres FROM tb_configuracion,"
                   + "tb_sede where tb_sede.id_prestador = tb_configuracion.id_prestador and "
                   + "tb_configuracion.id_prestador="+id;

            PreparedStatement stmt = conn.prepareStatement(sql);

            ResultSet res = stmt.executeQuery();
            ConfigVO configVO = new ConfigVO();
            if (res.next()) {
                     configVO.setRutalogo(res.getString("rutalogo"));
                     configVO.setRutarips(res.getString("rutarips"));
                     configVO.setCons_actfact(res.getInt("cons_actfact"));
                     configVO.setPrefijo_fact(res.getString("prefijo_fact"));
                     configVO.setCons_inifact(res.getInt("cons_inifact"));
                     configVO.setCons_finfact(res.getInt("cons_finfact"));
                     configVO.setCod_ips(res.getString("codigo"));
                     configVO.setCod_pres(res.getString("cod_pres"));
            }

         res.close();
         stmt.close();
         if (!conn.isClosed())
               conn.close();



        return configVO;
    }

    
   

}
